import Vue from 'vue'
import App from './App'
import store from './store/index.js'

Vue.config.productionTip = false

App.mpType = 'app'

import setting from 'setting.js';
Vue.use(setting);

// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView);

// 一些时间方法
import dateMeans from '@/common/dateMeans.js';
Vue.use(dateMeans);

// 一些全局过滤方法
import overallFilter from '@/common/overallFilter.js';
Vue.use(overallFilter);

// 国际化
import VueI18n from 'vue-i18n';
Vue.use(VueI18n)
import messages from './locale/index';
let i18nConfig = {
	locale: uni.getLocale(),
	messages,
}
const i18n = new VueI18n(i18nConfig)

 // 分享
import share from '@/common/share.js'
Vue.mixin(share)


/**
 * 获取访客
 */
Vue.prototype.getVisitcode = function() {
	let visitcode = uni.getStorageSync('visitcode');
	if (!visitcode) {
		visitcode = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
			var r = Math.random() * 16 | 0,
				v = c == 'x' ? r : (r & 0x3 | 0x8);
			return v.toString(16);
		});
		visitcode = visitcode.replace(/-/g, "");
		uni.setStorageSync('visitcode', visitcode);
	}

	return visitcode;
};

Vue.prototype.$onLaunched = new Promise(resolve => {
    Vue.prototype.$isResolve = resolve
})

const app = new Vue({
	store,
	i18n,
	...App
})

// http拦截器，将此部分放在new Vue()和app.$mount()之间，才能App.vue中正常使用
import httpInterceptor from '@/request/http.interceptor.js';
Vue.use(httpInterceptor, app);

// http接口API抽离，免于写url或者一些固定的参数
import httpApi from '@/request/http.api.js';
Vue.use(httpApi, app);

app.$mount()